package com.fanbai.score.user.activity;

import android.text.Html;
import android.view.View;
import android.widget.TextView;

import com.fanbai.score.R;
import com.fanbai.score.common.Manager.ActivityManager;
import com.fanbai.score.common.Utils.ToastUtils;
import com.fanbai.score.common.base.BaseActivity;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.user.bean.DuiHuanGRB_Bean;
import com.fanbai.score.user.http.UserScorea_RequestNet_Utils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by acer on 2017/5/13.
 * 兑换贵人币
 */

public class ElegantExchange_Activity extends BaseActivity{

    @BindView(R.id.userActivityElegantexChange_basevalue)
    TextView baseValue;
    @BindView(R.id.userActivityElegantexChange_allScore)
    TextView allScore;
    @BindView(R.id.userActivityElegantex_keDuiHuan)
    TextView keduihuanText;
    @BindView(R.id.userActivityElegantex_duiHuanGuiZe)
    TextView duihuanguizeText;

    @OnClick(R.id.userActivityElegantex_keDuiHuan)
    public void laodGuiZe(){
        if(duihuanguizeText.getVisibility() == View.VISIBLE){
            duihuanguizeText.setVisibility(View.GONE);
        }else{
            duihuanguizeText.setVisibility(View.VISIBLE);
        }
    }
    @OnClick(R.id.userActivityElegantex_duiHuanBut)
    public void dhBut(){
        exchargecoin();
    }

    @Override
    protected int getLayoutID() {
        return R.layout.user_activity_elegantexchange;
    }

    @Override
    public String getTitleName() {
        return "兑换贵人币";
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData() {
        getscoreexchargestat();
    }

    @Override
    protected void initListener() {

    }

    private void setViewData(DuiHuanGRB_Bean bean){
        baseValue.setText("今日返款值："+bean.getBasevalue());
        allScore.setText("您可兑换的总积分:"+bean.getTotalscore());
        keduihuanText.setText("可兑换"+bean.getRechargablecoin()+"贵人币");
        duihuanguizeText.setText(Html.fromHtml(bean.getDesc()));
    }

    @Override
    public int getTitleLeftName() {
        return R.mipmap.back_click;
    }

    @Override
    public void onClickTitleLeft() {
        ActivityManager.getInstance().finishActivity();
    }


    private void getscoreexchargestat(){
        showDialog();
        UserScorea_RequestNet_Utils.getscoreexchargestat(ctx, new CallBack<DuiHuanGRB_Bean>() {
            @Override
            public void onSuccess(String code, String msg, DuiHuanGRB_Bean bean) {
                hideDialog();
                setViewData(bean);
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }
        });
    }

    private void exchargecoin(){
        showDialog();
        UserScorea_RequestNet_Utils.exchargecoin(ctx, new CallBack<String>() {
            @Override
            public void onSuccess(String code, String msg, String s) {
                hideDialog();
                ToastUtils.RightImageToast(ctx, msg);
                ActivityManager.getInstance().finishActivity();
            }

            @Override
            public void onFailure(String code, String msg, String body) {
                hideDialog();
                ToastUtils.WarnImageToast(ctx, msg);
            }

            @Override
            public void onError(String code, String msg) {
                hideDialog();
                ToastUtils.ErrorImageToast(ctx, msg);
            }
        });
    }
}
